home *** CD-ROM | disk | FTP | other *** search
- unit PackPeek;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls;
-
- type
- TForm1 = class(TForm)
- OpenDialog: TOpenDialog;
- CurrentFile: TLabel;
- Button1: TButton;
- Bevel1: TBevel;
- UnitList: TListBox;
- Label1: TLabel;
- PackageList: TListBox;
- Label2: TLabel;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- function FormatPathToFit (const fName: String; Canvas: TCanvas; AvailWidth: Integer): String;
- var
- Idx: Integer;
- Drive: String[4];
- Path, Name, Ext: String;
-
- procedure ShortenPath;
- var
- StartSlash: Boolean;
- begin
- if Path = '\' then Path := '' else begin
- if Path[1] = '\' then begin
- StartSlash := True;
- Path := Copy (Path, 2, 255);
- end
- else StartSlash := False;
-
- if Path[1] = '.' then Path := Copy (Path, 5, 255);
-
- Idx := Pos ('\', Path);
- if Idx <> 0 then Path := '...\' + Copy (Path, Idx + 1, 255)
- else Path := '';
-
- if StartSlash then Path := '\' + Path;
- end;
- end;
-
- begin
- Result := fName;
- Path := ExtractFilePath (Result);
- Name := ExtractFileName (Result);
- Idx := Pos ('.', Name);
- if Idx > 0 then SetLength (Name, Idx - 1);
- Ext := ExtractFileExt (Result);
- if Path [2] = ':' then begin
- Drive := Copy (Path, 1, 2);
- Path := Copy (Path, 3, 255);
- end
- else Drive := '';
-
- while ((Path <> '') or (Drive <> '')) and (Canvas.TextWidth (Result) > AvailWidth) do
- begin
- if Path = '\...\' then begin
- Drive := '';
- Path := '...\';
- end
- else if Path = '' then Drive := ''
- else ShortenPath;
-
- Result := Drive + Path + Name + Ext;
- end;
- end;
-
- procedure PackageCallback (const ModuleName: string; NameType: TNameType; Flags: Byte; Param: TForm1);
- begin
- with Param do begin
- if NameType = ntContainsUnit then
- UnitList.Items.Add (ModuleName)
- else
- PackageList.Items.Add (ModuleName);
- end;
- end;
-
- procedure TForm1.Button1Click (Sender: TObject);
- var
- hLib: hModule;
- PackageFlags: Integer;
- begin
- if OpenDialog.Execute then begin
- UnitList.Clear;
- PackageList.Clear;
- CurrentFile.Caption := FormatPathToFit (OpenDialog.FileName, Canvas, CurrentFile.Width);
- hLib := LoadLibrary (PChar (OpenDialog.FileName));
- if hLib <> 0 then try
- { If we get here, it's a 32-bit executable }
- try
- GetPackageInfo (hLib, Self, PackageFlags, @PackageCallback);
- except
- { If executable has no PackageInfo resource, just bow out }
- Exit;
- end;
- finally
- FreeLibrary (hLib);
- end;
- end;
- end;
-
- end.
-
-